home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / BOOTUP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-15  |  19.7 KB  |  771 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <VDI.H>
  9. #include <OSBIND.H>
  10. #include <MINTBIND.H>
  11. #include <UNISTD.H>
  12. #include <FILESYS.H>
  13. #include <SIGNAL.H>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <ostruct.h>
  18. #include "xa_defs.h"
  19. #include "k_defs.h"
  20. #include "xa_types.h"
  21. #include "frm_alrt.h"
  22. #include "handler.h"
  23. #include "cookies.h"
  24. #include "kernal.h"
  25. #include "mouse_cl.h"
  26. #include "c_window.h"
  27. #include "std_widg.h"
  28. #include "XA_GLOBL.H"
  29. #include "system.h"
  30. #include "signals.h"
  31. #include "shellwrt.h"
  32. #include "resource.h"
  33. #include "rectlist.h"
  34. #include "objects.h"
  35. #include "about.h"
  36. #include "DESKTOP.H"
  37. #include "F_XBIOS.H"
  38. #include "kernal.h"
  39. #include "scrlobjc.h"
  40.  
  41. /* aes.h confilcts with k_defs.h, so we can't use it here... :-( */
  42. #if defined(LATTICE)        /* ----- Lattice C ----- */
  43. extern short _AESglobal[15];
  44. #define global _AESglobal
  45. int __regargs _AESif(unsigned int);
  46. #define appl_init() _AESif(0)
  47. extern int graf_handle(short *,short *,short *,short *);
  48. #define appl_exit()    _AESif(36)
  49. #elif defined(__PUREC__)    /* ----- Pure C 1.1 ----- */
  50. typedef struct
  51. {
  52.     int        contrl[15];
  53.     int        global[15];
  54.     int        intin[132];
  55.     int        intout[140];
  56.     void    *addrin[16];
  57.     void    *addrout[16];
  58. } GEMPARBLK;
  59. extern  GEMPARBLK _GemParBlk;
  60. #define global _GemParBlk.global
  61. extern int appl_init(void);
  62. extern int graf_handle(int *,int *,int *,int *);
  63. extern int appl_exit(void);
  64. #else                        /* ----- others ----- */
  65. extern short global[] ;
  66. extern int appl_init(void) ;
  67. extern int graf_handle(int *,int *,int *,int *);
  68. extern int appl_exit(void);
  69. #endif
  70.  
  71. /*
  72.     Boot up code
  73. */
  74.  
  75. const char select_ink[]={27,'b',0};
  76. const char select_paper[]={27,'c',0};
  77.  
  78. void _XCEXIT(void)
  79. {
  80.     exit(0);
  81. }
  82.  
  83. void BootMessage(void)
  84. {
  85.     printf("XaAES ");
  86.     printf(XA_VERSION);
  87.     printf("\nMultiTasking AES for MiNT\n");
  88.     printf("(w)1995,96, Craig Graham, Johan Klockars, Martin Koehling, Thomas Binder\n");
  89.     printf("   and other assorted dodgy characters from around the world...\n");
  90.     printf("Date: %s\n",__DATE__);
  91.     printf("Compile time switches enabled:\n");
  92.  
  93. #if GENERATE_DIAGS
  94.     printf(" - Diagnostics\n");
  95. #endif
  96.  
  97. #if FORCE_WINDOWS
  98.     printf(" - Force windows\n");
  99. #endif
  100.  
  101. #if SOLID_BOXES
  102.     printf(" - Solid boxes\n");
  103. #endif
  104.  
  105. #if MONO_WIDGETS
  106.     printf(" - Mono widgets\n");
  107. #else
  108.     printf(" - Colour widgets\n");
  109. #endif
  110.         
  111. #if DISPLAY_LOGO_IN_TITLE_BAR
  112.     printf(" - Logo in title bar\n");
  113. #endif
  114.  
  115. #if POINT_TO_TYPE
  116.     printf(" - Point-to-type\n");
  117. #endif
  118.  
  119. #if ALT_CTRL_APP_OPS
  120.     printf(" - CTRL+ALT key-combo's\n");
  121. #endif
  122.  
  123. #if USE_CALL_DIRECT
  124.     printf(" - Use direct-call\n");
  125. #endif
  126.  
  127. #if AVOID_MINT_PIPES_BUG
  128.     printf(" - Avoid MiNT pipe delete bug\n");
  129. #endif
  130.  
  131. #if EMULATE_AES4_1
  132.     printf(" - Emulate AES4.1\n");
  133. #else
  134.     printf(" - Emulate AES1.4\n");
  135. #endif
  136.  
  137. #if DODGY_MEMORY_PROTECTION
  138.     printf(" - Dodgy OS_SPECIAL memory access\n");
  139. #endif
  140.  
  141. #if DEBUG_MALLOCS
  142.     printf(" - Use cmalloc(m,1) instead of malloc(m)\n");
  143. #endif
  144.  
  145. #if REALTIME_SCROLL
  146.     printf(" - Realtime (live) window scrolling\n");
  147. #endif
  148.  
  149. #if PRESERVE_DIALOG_BGD
  150.     printf(" - Preserve dialog backgrounds\n");
  151. #endif
  152.  
  153. #if OLD_NVDI
  154.     printf(" - NVDI2.5 compatibility\n");
  155. #endif
  156.  
  157. #if DYNAMIC_CLIENT_STRUCTURE
  158.     printf(" - Dynamic Client Structures\n");
  159. #else
  160.     printf(" - Static Client Array\n");
  161. #endif
  162.  
  163.     printf("\n");
  164. }
  165.  
  166. short P_handle=0,V_handle=0;        /* Workstation handles used by the AES */
  167. XA_SCREEN display;                    /* The display descriptor */
  168. const XA_COLOUR_SCHEME default_colours={LWHITE,BLACK,LBLACK,WHITE,BLACK,CYAN};
  169. const XA_COLOUR_SCHEME bw_default_colours={WHITE,BLACK,BLACK,BLACK,BLACK,BLACK};
  170. far long AES_in_pipe;                    /* The AES instruction input pipe handle */
  171. unsigned long client_handle_mask=0L;    /* Mask of all active client pipes for Fselect */
  172.  
  173. far long MOUSE_dev=0L;                        /* The /dev/mouse handle */
  174. short double_click_time=DOUBLE_CLICK_TIME;    /* double click timing */
  175.  
  176. long KBD_device;                    /* The MiNT keyboard device's file handle */
  177.  
  178. short AESpid;                        /* The AES's MiNT process ID */
  179.  
  180. XA_WINDOW *root_window;                /* The desktop window */
  181.  
  182. #if GENERATE_DIAGS
  183. char debug_path[100];                /* Path to dump debug info to */
  184. short debug_file;                    /* File handle to dump debug stuff to */
  185. #endif
  186.  
  187. char XaAES_home[200];                /* XaAES's home location */
  188. short XaAES_home_drv;
  189.  
  190. char scrap_path[128];                /* Path to the scrap directory */
  191. char acc_path[128];                    /* Path to desk accessory directory */
  192.  
  193. void *system_resources;                /* Pointer to the XaAES resources */
  194. const char dummy_cmd_tail[]="\0";     /* Dummy constants used for distinguishing */
  195. const char dummy_cmd_name[]="";     /* malloced from non-malloced strings... */
  196.  
  197. short iconify_x,iconify_y,iconify_w,iconify_h;    /* Positioning information for iconifying windows */
  198.  
  199. /*
  200.     Read & parse the 'xaaes.cnf' file.
  201. */
  202. void parse_cnf(void)
  203. {
  204.     FILE *cnf;
  205.     char lb[210],parms[200],*p;
  206.     short tl,t;
  207.     
  208.     lb[202]='\0';
  209.     
  210.     cnf=fopen("xaaes.cnf","r");
  211.     if (!cnf)
  212.     {
  213.         cnf=fopen("u:\\c\\mint\\xaaes.cnf","r");
  214.         if (!cnf)
  215.         {
  216.             cnf=fopen("u:\\c\\multitos\\xaaes.cnf","r");
  217.             if (!cnf)
  218.             {
  219.                 cnf=fopen("u:\\c\\xaaes.cnf","r");
  220.                 if (!cnf)
  221.                 {
  222.                     DIAGS(("WARNING: Couldn't open xaaes.cnf\n"));
  223.                     return;
  224.                 }
  225.             }
  226.         }
  227.     }
  228.  
  229.     while(!feof(cnf))
  230.     {
  231.         fgets(lb,199,cnf);
  232.         
  233.         if (lb[0]!='#')                            /* '#' is a comment line */
  234.         {
  235.             tl=strlen(lb);
  236.             
  237.             for(t=0; (t<tl)&&(lb[t]!=' '); t++) 
  238.                 if ((lb[t]>96)&&(lb[t]<123))    /* Capitalise the command */
  239.                     lb[t]-=32;
  240.  
  241.             for(t++; t<tl; t++)
  242.             {
  243.                 if (lb[t]<14)                    /* Strip out unwanted carriage returns, etc */
  244.                     lb[t]='\0';
  245.             }
  246.             
  247.             if (!strncmp(lb,"RUN ",4))            /* Run command launches a program */
  248.             {
  249.                 for(p=lb+4; (*p!=' ')&&(*p!='\0'); p++);
  250.                 if (*p)
  251.                 {
  252.                     *p='\0';
  253.                     p++;
  254.                 }
  255.                 sprintf(parms+1,"%s",p);
  256.                 parms[0]=(char)strlen(parms+1);
  257.                 
  258.                 shell_write(0,0,0,lb+4,parms);
  259.             }
  260.             
  261.             if (!strncmp(lb,"CLIPBOARD ",10))    /* Set the location of the default clipboard */
  262.             {
  263.                 sprintf(scrap_path,"%s",lb+10);
  264.             }
  265.  
  266.             if (!strncmp(lb,"ACCPATH ",8))    /* Set the location of the default clipboard */
  267.             {
  268.                 sprintf(acc_path,"%s",lb+8);
  269.             }
  270.  
  271.             if (!strncmp(lb,"DC_TIME ",8))    /* Set the default double click timing */
  272.             {
  273.                 sscanf(lb+8,"%i",&double_click_time);
  274.             }
  275.             
  276. #if GENERATE_DIAGS
  277.             if (!strncmp(lb,"DEBUG ",6))        /* Redirect console output */
  278.             {
  279.                 sprintf(debug_path,"%s",lb+6);
  280.             }
  281. #endif
  282.         }
  283.     }
  284. }
  285.  
  286. void load_accs(void)
  287. {
  288.     char search_path[200];
  289.     char acc[200];
  290.     short fnd;
  291.     _DTA *my_dta=Fgetdta();
  292.     
  293.     sprintf(search_path,"%s*.ACC",acc_path);
  294.  
  295.     fnd=Fsfirst(search_path,0xff);
  296.     while(!fnd)
  297.     {
  298.         sprintf(acc,"%s%s",acc_path,my_dta->dta_name);
  299.         shell_write(3,0,0,acc,"");
  300.         fnd=Fsnext();
  301.     }
  302. }
  303.  
  304. static short auto_program ;
  305.  
  306. /*
  307.     Cleanup on exit
  308.     - this is pretty iffy at the moment, but it will get you back to a command line.
  309.       (you cann't re-start XaAES again though :( )
  310. */
  311. static void Cleanup(void)
  312. {
  313.     XA_CLIENT *client;
  314.     long ex_con;
  315.     
  316.     DIAGS(("Cleaning up ready to exit....\n"));
  317.     Psignal(SIGCHLD, 0L);
  318.     
  319. /* Kill off clients */
  320.     for(client=FirstClient(); client!=NULL; client=NextClient(client))
  321.     {
  322.         if (client->clnt_pipe_rd)
  323.         {
  324.             DIAGS(("Killing:%d:%s:%s\n",Client2Pid(client),client->cmd_name,client->name));
  325.             Pkill(Client2Pid(client),SIGTERM);
  326.         }
  327.     }
  328.  
  329.     Syield();
  330.     
  331.     for(client=FirstClient(); client!=NULL; client=NextClient(client))
  332.     {
  333.         if (client->clnt_pipe_rd)
  334.         {
  335.             ex_con=Pwaitpid(Client2Pid(client),1,NULL);        /* if client ignored SIGTERM, send SIGKILL */
  336.             if (!ex_con)
  337.             {
  338.                 Pkill(Client2Pid(client),SIGKILL);
  339.             }
  340.         }
  341.     }
  342.  
  343. /* Close the mouse device */
  344.     Fclose(MOUSE_dev);
  345.  
  346. /* Close screen workstation */
  347.     v_clsvwk(V_handle);
  348.     if ( auto_program )
  349.         v_clswk(P_handle);    /* Auto version must close the physical workstation */
  350.  
  351. /* Close the AES command pipe (server end) */
  352.     Fclose(AES_in_pipe);
  353.     
  354. /* Unhook from the trap vector */
  355.     unhook_from_vector() ;
  356.     
  357. /* Remove semaphores: */
  358.     Psemaphore(1,APPL_INIT_SEMAPHORE,0);
  359.     Psemaphore(1,TRAP_HANDLER_SEMAPHORE,0);
  360.     Psemaphore(1,WIN_LIST_SEMAPHORE,0);
  361.     Psemaphore(1,ROOT_SEMAPHORE,0);
  362.     Psemaphore(1,CLIENTS_SEMAPHORE,0);
  363.     Psemaphore(1,UPDATE_LOCK,0);
  364.     Psemaphore(1,MOUSE_LOCK,0);
  365.     Psemaphore(1,FSELECT_SEMAPHORE,0);
  366.     if ( !auto_program )    /* If we weren't an auto program, call appl_exit() to the standard AES */
  367.         appl_exit() ;
  368. }
  369.  
  370. /*
  371.     (Re)initialise the mouse device /dev/moose
  372. */
  373. short init_moose(void)
  374. {
  375.     MOOSE_INIT_COM i_com;
  376.     MOOSE_DCLICK_COM dc_com;
  377.  
  378.     DIAGS(("Moose init\n"));
  379.  
  380.     if (!MOUSE_dev)
  381.     {
  382.         MOUSE_dev=Fopen("u:\\dev\\moose", O_RDWR);
  383.         if (MOUSE_dev<0)
  384.         {
  385.             DIAGS(("Cann't open /dev/moose?\n"));
  386.             return 0;
  387.         }
  388.     }
  389.     
  390.     i_com.init_prefix=MOOSE_INIT_PREFIX;    /* load the command prefix into the command */
  391.     i_com.ikbd_table=(void*)Kbdvbase();        /* load the pointer to the IKBD table into the command */
  392.     
  393.     DIAGS((" handle=%d\n",MOUSE_dev));
  394.     
  395.     DIAGS(("ikbd_table=%lx\n",i_com.ikbd_table));
  396.  
  397.     if (Fwrite(MOUSE_dev,6L,&i_com)==0)
  398.     {
  399.         DIAGS(("moose init failled\n"));
  400.     }
  401.  
  402.     dc_com.dclick_prefix=MOOSE_DCLICK_PREFIX;
  403.     dc_com.dclick_time=50;
  404. /*    dc_com.dclick_time=double_click_time;*/
  405.     if (Fwrite(MOUSE_dev,4L,&dc_com)==0)
  406.     {
  407.         DIAGS(("moose set dclick time failled\n"));
  408.     }
  409.  
  410.     return 1;
  411. }
  412.  
  413.  
  414. /*
  415.     Startup & Initialisation....
  416.     - Spawn off any extra programs we need (mouse server, etc).
  417.     - Open physical & virtual workstations.
  418.     - Install our trap handler.
  419.     - Run the xaaes.cnf startup script.
  420. */
  421.  
  422. const XA_WIDGET_LOCATION sys_menu_loc={LT,2,2};
  423.  
  424. short main(short argc, char *argv[])
  425. {
  426.     short work_in[12];
  427.     short work_out[58];
  428.     char a1[10];
  429.     short f,junk;
  430.     long dummy;
  431.     XA_WIDGET_TREE *menu;
  432. #if DODGY_MEMORY_PROTECTION
  433.     short proc_handle;
  434.     long protection;
  435. #endif
  436.  
  437. /* Check that MiNT is actually installed */
  438.     if(!GetCookie((long)'MiNT',&dummy))
  439.     {
  440.         BootMessage();
  441.         /* Use puts here, as everything is not yet initialised */
  442.         puts("Sorry, XaAES requires MiNT to run.");
  443.         exit(1);
  444.     }
  445.  
  446. /* Let's get our MiNT process id being's as MiNT is loaded... */
  447.     AESpid=Pgetpid();
  448.     clients[AESpid].cmd_name="XaAES";
  449.  
  450. /* Change the protection mode to OS_SPECIAL to allow operation with
  451.  * memory protection (doesn't work yet, what's wrong?)
  452.  */
  453. /* Craig's Note: I think this causes a massive memory leak in the MiNT kernal, so
  454.    I've disabled it */
  455.  #if DODGY_MEMORY_PROTECTION
  456.     {
  457. #ifndef F_PROT_S
  458. #define F_PROT_S        0x20
  459. #endif
  460. #ifndef F_OS_SPECIAL
  461. #define F_OS_SPECIAL    0x8000
  462. #endif
  463.         /*    Opening "u:\proc\.-1" opens the current process... */
  464.         if ((dummy = Fopen("u:\\proc\\.-1", O_RDONLY)) >= 0)
  465.         {
  466.             proc_handle = (short)dummy;
  467.             Fcntl(proc_handle, &protection, PGETFLAGS);
  468.             protection &= ~0xf0;
  469.             protection |= F_OS_SPECIAL | F_PROT_S;
  470.             Fcntl(proc_handle, &protection, PSETFLAGS);
  471.             Fclose(proc_handle);
  472.         }
  473.     }
  474. #endif
  475.  
  476. /* Where were we started? */
  477.     XaAES_home_drv=Dgetdrv();
  478.     Dgetcwd(XaAES_home,XaAES_home_drv+1,sizeof(XaAES_home)-1);
  479.  
  480. /* Are we an auto/mint.cnf launched program? */
  481.     /* Note: global[0] (AES version number) is initially zero. */
  482.     appl_init();
  483.     auto_program=(global[0]==0);    /* global[0] still zero? */
  484.     
  485.     for(f=1;f<10; work_in[f++]=1);
  486.     work_in[10]=2;
  487.     
  488.     if (auto_program)
  489.     {
  490.         printf("auto program\n");
  491.  
  492.         if ( (Kbshift(-1)&3) && Getrez()==0 )             /* any shift key and low rez */
  493.         {
  494.             Setscreen((void*)-1L,(void*)-1L,1);         /* switch to medium rez */
  495.         }else{
  496.  
  497.             /* Set video mode from command line parameter ?*/
  498.             if (argc>2)
  499.             {
  500.  
  501.                 if (!strcmp("-fvideo",argv[1]))             /* Falcon Video mode switch */
  502.                 {
  503.                     short modecode=atoi(argv[2]);
  504.  
  505.                     if ((GetCookie((long)'_VDO',&dummy))&&(dummy>=0x00030000L))
  506.                     {
  507.                         VsetScreen((void*)-1L,(void*)-1L,3,modecode);
  508.                     }
  509.  
  510.                     work_in[0]=1;
  511.                     v_opnwk(work_in,&P_handle,work_out);
  512.                     
  513.                     DIAGS(("Set falcon video: mode=%d\n",modecode));
  514.                     
  515.                 }else{
  516.  
  517.                     if (!strcmp("-video",argv[1]))             /* Video mode switch */
  518.                     {
  519.                         short modecode=atoi(argv[2]);
  520.  
  521.                         work_in[0]=modecode;
  522.                         v_opnwk(work_in,&P_handle,work_out);
  523.                     }else{
  524.                         work_in[0]=Getrez()+2;
  525.                         v_opnwk(work_in,&P_handle,work_out);            /* If we are an auto program we must open a physical workstation to the screen */
  526.                     }
  527.                 }
  528.             }
  529.         }
  530.  
  531.     }else{
  532.  
  533.         P_handle=graf_handle(&junk,&junk,&junk,&junk);    /* The GEM AES has already been started,  */
  534.                                                         /*  so get the physical workstation handle from it */
  535.     }
  536.  
  537.  
  538. /* Setup the kernal OS call jump table */
  539.     setup_k_function_table();
  540.  
  541. /* Create a whole wodge of semphores for everything from remembering your mothers birthday
  542.    to avoiding an IRA bomb up your arse at work......(yes folks, I work in London and
  543.    don't like getting blown up). */
  544.     Psemaphore(0,APPL_INIT_SEMAPHORE,0);
  545.     Psemaphore(0,TRAP_HANDLER_SEMAPHORE,0);
  546.     Psemaphore(0,WIN_LIST_SEMAPHORE,0);
  547.     Psemaphore(0,ROOT_SEMAPHORE,0);
  548.     Psemaphore(0,CLIENTS_SEMAPHORE,0);
  549.     Psemaphore(0,UPDATE_LOCK,0);
  550.     Psemaphore(0,MOUSE_LOCK,0);
  551.     Psemaphore(0,FSELECT_SEMAPHORE,0);
  552.  
  553. /* Print a text boot message */
  554.     BootMessage();
  555.  
  556. /* Patch the AES trap vector to use our OS. */
  557.     hook_into_vector();
  558.  
  559. /* Create the XaAES.cmd introduction pipe */
  560.     AES_in_pipe=Fopen("u:\\pipe\\XaAES.cmd",O_CREAT|O_RDWR);
  561.  
  562. /* Open the u:/dev/console device to get keyboard input */
  563.     KBD_device=Fopen("u:\\dev\\console",O_RDONLY);
  564.     if (KBD_device<0)
  565.     {
  566.         printf("XaAES ERROR: Can't open /dev/console ?\n");
  567.         Cleanup() ;
  568.         return 1;
  569.     }
  570.  
  571. /* Initialise the client descriptors */
  572.     for(f=0; f<MAX_PID; f++)
  573.     {
  574.         clients[f].clnt_pipe_rd=clients[f].clnt_pipe_wr=0;
  575.         clients[f].std_resource=NULL;
  576.         clients[f].parent=AESpid;
  577.         clients[f].cmd_tail=(char*)dummy_cmd_tail;
  578.         clients[f].cmd_name=(char*)dummy_cmd_name;
  579.         clients[f].zen=NULL;
  580.         clients[f].desktop=NULL;
  581.     }
  582.  
  583. /* Open us a virtual workstation for XaAES to play with */
  584.     V_handle=P_handle;
  585.     v_opnvwk(work_in,&V_handle,work_out);
  586.     vswr_mode(V_handle,MD_TRANS);    /* We run in TRANSPARENT mode for all AES ops (unless requested otherwise) */
  587.     vst_alignment(V_handle,0,5,&f,&f);
  588.  
  589. /*     Setup the display parameters */
  590.     display.x=display.y=0;
  591.     display.w=work_out[0];
  592.     display.h=work_out[1];
  593.     display.colours=work_out[13];
  594.     display.display_type=D_LOCAL;
  595.     display.P_handle=P_handle;
  596.     display.V_handle=V_handle;
  597.  
  598.     display.dial_colours=
  599.         (display.colours<16) ?    bw_default_colours : default_colours;
  600.     
  601.     vq_extnd(V_handle,1,work_out);    /* Get extended information */
  602.     display.planes=work_out[4];        /* number of planes in the display */
  603.  
  604. /* If we are using anything apart from the system font for windows, better check 
  605.    for GDOS and load the fonts. */
  606.     if (STANDARD_AES_FONTID!=1)        
  607.     {
  608.         if (vq_gdos())        /* Yeah, I know, this is assuming the old-style vq_gdos() binding */
  609.             vst_load_fonts(V_handle,0);
  610.     }
  611.  
  612. /* Set standard AES font */
  613.     display.standard_font_id = display.small_font_id =
  614.         vst_font(V_handle,STANDARD_AES_FONTID);
  615.  
  616. /* Select Small font */
  617.     display.small_font_point = vst_point(V_handle,
  618.         SMALL_FONT_POINT, &f, &display.small_font_height, &f, &f);
  619.         
  620. /* Select standard font */
  621.      display.standard_font_point = vst_point(V_handle,
  622.          (display.h<=280) ? 9 : STANDARD_FONT_POINT,
  623.         &f, &display.standard_font_height,
  624.         &f, &f);
  625.  
  626. /* Get font information for use by the resource loader */
  627.     vqt_attributes(V_handle, work_out) ;
  628.     display.c_max_w=work_out[8];    /* character cell width */
  629.     display.c_max_h=work_out[9];    /* character cell height */
  630.  
  631. /* Initialise the object tree display routines */
  632.     init_objects();
  633.  
  634. /* Set the default clipboard */
  635.     strcpy(scrap_path,"c:\\clipbrd\\");
  636. /* Set the default accessory path */
  637.     strcpy(acc_path,"c:\\");
  638.  
  639.     sprintf(a1,"%d",P_handle);
  640.  
  641. #if SHOW_LOGO_AT_STARTUP
  642. /* Display the XaAES logo */
  643.     if (!Pvfork())
  644.     {                /* In child here */
  645.         execl("logo.prg","XaAES_LOGO",NULL);
  646.     }
  647. #endif
  648.  
  649. /* Parse the standard startup file xaaes.cnf
  650.    This can run programs & re-direct the debugging output to another file/device */
  651. #if GENERATE_DIAGS
  652.     strcpy(debug_path,"debug.list");    /* By default debugging output goes to the file "./debug.list"*/
  653. #endif
  654.     parse_cnf();
  655.  
  656. #if GENERATE_DIAGS
  657. /* Open a diagnostics file? All console output can be considered diagnostics, so
  658.    I just redirect the console to the required file/device */
  659.     debug_file=(int)Fopen(debug_path,O_CREAT|O_WRONLY);
  660.     Fforce(1,debug_file);
  661.  
  662.     DIAGS(("\n\n\nDebug to %s\n",debug_path));
  663. #endif
  664.  
  665.     DIAGS(("Display Device: P_handle=%d, V_handle=%d\n",P_handle,V_handle));
  666.     DIAGS((" size=[%d,%d], colours=%d, bitplanes=%d\n",display.w,display.h,display.colours,display.planes));
  667.  
  668. /* Load the system resource file (we can probably embed this later) */
  669.     system_resources=LoadResources("system.rsc",DU_RSX_CONV, DU_RSY_CONV);
  670.     if (system_resources)
  671.     {
  672.         DIAGS(("system_resources=%lx\n",system_resources));
  673.     }else{
  674.         puts("ERROR: Cann't find/load system resource file 'system.rsc'\n");
  675.         Cleanup();
  676.         return -1;
  677.     }
  678.     
  679. /* Create the root (desktop) window 
  680.     - we don't want messages from it, so make it a NO_MESSAGES window */
  681.  
  682.     DIAGS(("creating root window\n"));
  683.  
  684.     root_window=create_window(AESpid, NO_MESSAGES, 0, 0, display.w, display.h);
  685.  
  686.     DIAGS(("done create root\n"));
  687.  
  688.     root_window->handle=0;
  689.     root_window->is_open=TRUE;                /* Flag window as open    */
  690.     
  691. /* Tack a menu onto the root widget */
  692.     clients[AESpid].std_menu=ResourceTree(system_resources,SYSTEM_MENU);
  693.     fix_menu(clients[AESpid].std_menu);
  694.     set_menu_widget(root_window, sys_menu_loc, clients[AESpid].std_menu);
  695.     menu=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  696.     menu->owner=AESpid;
  697.  
  698. #if 0
  699. /* Fix up the file selector menu */
  700.     fix_menu(ResourceTree(system_resources,FSEL_MENU));
  701. #endif
  702.  
  703. /* Standard Widget Set from resource file */
  704.     def_widgets=ResourceTree(system_resources,WIDGETS);
  705.  
  706. /* Fix up the window widget bitmaps and any others we might be using
  707.    (calls vr_trnfm() for all the bitmaps) */
  708.     fix_bitmaps();
  709.  
  710. /* Set a default desktop */
  711.     set_desktop(ResourceTree(system_resources,DEF_DESKTOP));
  712.     (desktop+DESKTOP_LOGO)->ob_x=(root_window->ww-(desktop+DESKTOP_LOGO)->ob_width)/2;
  713.     (desktop+DESKTOP_LOGO)->ob_y=(root_window->wh-(desktop+DESKTOP_LOGO)->ob_height)/2;
  714.     clients[AESpid].desktop=desktop;
  715.  
  716. /* Setup the task manager */
  717. {
  718.     OBJECT *form=ResourceTree(system_resources,TASK_MANAGER);
  719.     set_scroll(form, TM_LIST, "Client Applications");
  720.     
  721.     form=ResourceTree(system_resources,FILE_SELECT);
  722.     set_scroll(form, FS_LIST, "File List");
  723. }
  724.  
  725. /* Display the root window */
  726.     v_hide_c(V_handle);
  727.     DIAGS(("calling display_non_topped_window()\n"))
  728.     display_non_topped_window(root_window,NULL);
  729.     DIAGS(("window displayed\n"));
  730.     generate_rect_list(root_window);
  731.     DIAGS(("calling display_non_topped_window()\n"))
  732.     display_non_topped_window(root_window,NULL);
  733.     DIAGS(("window displayed\n"));
  734.     
  735. /* Initial iconified window coords */
  736.     iconify_w=ICONIFIED_W; iconify_h=ICONIFIED_H;
  737.     iconify_x=0;
  738.     iconify_y=display.y+display.h-iconify_h-1;
  739.  
  740. /* Turn on the mouse cursor */
  741.     v_show_c(V_handle,0);
  742.  
  743. /* Set our process priority - a high negative value here improves performance a lot, 
  744.    so I set it to -20 in XA_DEFS.H. This doesn't hurt the rest of the systems performance,
  745.    as there are no busy wait loops in the server, and it spends most of it's time blocked
  746.    waiting for commands. */
  747.  
  748.     Pnice(AES_PRIORITY);
  749.  
  750. /* Catch SIGCHLD to spot dead children */
  751.     Psignal(SIGCHLD, (long)HandleSIGCHLD);
  752.  
  753. /* Load Accessories */
  754.     load_accs();
  755.     
  756. /* Catch SIGINT and SIGQUIT so we can shutdown with CTRL+ALT+C */
  757.     Psignal(SIGINT, (long)HandleSIGINT);
  758.     Psignal(SIGQUIT, (long)HandleSIGINT);
  759.  
  760. /* Open /dev/moose */
  761.     init_moose();
  762.  
  763. /* Call the main command interpreter kernal */
  764.     kernal();
  765.  
  766. /* Closedown & exit */
  767.     Cleanup() ;
  768.  
  769.     return 0;
  770. }
  771.